package com.dream.tihai.controller;

import com.dream.tihai.entity.AskEntity;
import com.dream.tihai.service.IAskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Valley
 * Created by Valley on 2022/9/5
 */
@RestController
@RequestMapping("ask")
@CrossOrigin(origins = "*", maxAge = 3600)
public class AskController {

    @Autowired
    IAskService askService;


    @RequestMapping("selectAll")
    public List<AskEntity> selectAll(Integer typeId){
        return askService.selectAll(typeId);
    }

    @RequestMapping("get")
    public void get(HttpServletResponse res) throws IOException {
        res.sendRedirect("http://westudy.life:12345/learn.html");
    }

    @RequestMapping("add")
    public void add(@RequestParam("title") String title,
                    @RequestParam("answer") String answer,
                    @RequestParam("typeId") Integer typeId){
        askService.add(title, answer, typeId);
    }


}
